package com.qibo.rechar;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.AsyncTask;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.qibo.baselib.base.BaseActivity;

import cn.bingoogolapple.qrcode.core.BGAQRCodeUtil;
import cn.bingoogolapple.qrcode.zxing.QRCodeEncoder;

/**
 * 充值二维码
 */
public class RechargeQRCodeActivity extends BaseActivity{

    private ImageButton imageButton;
    private TextView textView_titleBar;
    private TextView textView_Right_titleBar;
    private ImageView mEnglishIv;
    @Override
    protected int getContentViewId() {
        return R.layout.rechargemodule_activity_rechargeqr;
    }

    @Override
    protected void initView() {
        imageButton = findViewById(R.id.btnBack_pay1);
        textView_titleBar = findViewById(R.id.textView_titleBar);
        textView_Right_titleBar = findViewById(R.id.textView_Right_titleBar);
        mEnglishIv = findViewById(R.id.rechargemodule_mEnglishIv);
    }

    @Override
    protected void initAction() {
        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();;
            }
        });
        textView_titleBar.setText("二维码充值");
    }

    @Override
    protected void initData() {
        createEnglishQRCode();
    }
    private void createEnglishQRCode() {
        new AsyncTask<Void, Void, Bitmap>() {
            @Override
            protected Bitmap doInBackground(Void... params) {
                return QRCodeEncoder.syncEncodeQRCode("200", BGAQRCodeUtil.dp2px(mContext, 150), Color.BLACK);
            }

            @Override
            protected void onPostExecute(Bitmap bitmap) {
                if (bitmap != null) {
                    mEnglishIv.setImageBitmap(bitmap);
                } else {
                    Toast.makeText(mContext, "生成英文二维码失败", Toast.LENGTH_SHORT).show();
                }
            }
        }.execute();
    }
}
